﻿<?xml version="1.0" encoding="utf-8" ?>

<cls:class
	name="EhciUsbController"
	type="http://metalx.org/Usb/Ehci/EhciUsbController"
	xmlns="http://metalx.org/Program"
	xmlns:cls="http://metalx.org/Class"
	xmlns:var="http://metalx.org/Variable"
	xmlns:clsf="http://metalx.org/i386/Functions/Class"
	xmlns:date="http://metalx.org/i386/Functions/Date"
	xmlns:time="http://metalx.org/i386/Functions/Time"
	xmlns:clk="http://metalx.org/i386/Functions/Clock"
	xmlns:obj="http://metalx.org/i386/Functions/Object"
	xmlns:sys="http://metalx.org/i386/Functions/System"
	xmlns:cat="http://metalx.org/i386/Functions/Catalog"
	xmlns:str="http://metalx.org/i386/Functions/String"
	xmlns:int="http://metalx.org/i386/Functions/Integer"
	xmlns:lst="http://metalx.org/i386/Functions/List"
	xmlns:pcif="http://metalx.org/i386/Functions/Pci"
	xmlns:hex="http://metalx.org/i386/Functions/Hexadecimal"
	xmlns:mm="http://metalx.org/i386/Functions/MemoryManager"
	xmlns:cpu="http://metalx.org/Intel/80386/Operators"
	xmlns:op="http://metalx.org/Intel/80386/Operands"
	xmlns:math="http://metalx.org/Intel/80386/Math"
	xmlns:ari="http://metalx.org/Intel/80386/Arithmetic"
	xmlns:shift="http://metalx.org/Intel/80386/Shift"
	xmlns:imm="http://metalx.org/Intel/80386/Immediate"
	xmlns:usb="http://metalx.org/Usb/Ohci/Registers"
	xmlns:pci="http://metalx.org/Pc/Pci/Ports"
	xmlns:cfg="http://metalx.org/Pc/Pci/Configuration">

	<cls:field name="Device" type="http://metalx.org/Pci/PciDevice" offset="0"/>

	<cls:method name="GetPorts" type="http://metalx.org/Usb/Ehci/EhciUsbPortList">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:PushAXToStack/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:AddImmediateToAX/>
		<int>4</int>

		<cpu:CopyOperandToRegister/>
		<op:AX-AXAddress/>

		<cpu:AndAXWithImmediate/>
		<hex>0000000f</hex>

		<cpu:PushAXToStack/>
		
		<!--Create List-->
		<lst:Create/>

		<!--<cpu:CompareAXToImmediate/>
		<int>0</int>

		<cpu:BranchToRelative8IfEqual/>
		<addressOf ref="createListObject" type="Relative8"/>-->

		<!--Find Class-->
		<cpu:PushDIToStack/>

		<sys:GetCatalog/>

		<cpu:CopyImmediateToDI/>
		<addressOf ref="ehciUsbPort" type="Absolute32"/>

		<cat:FindType/>

		<cpu:PullDXFromStack/>

		<cpu:PullCXFromStack/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-BXRegister/>

		<!--Create Objects-->
		<label id="forEachDevice"/>

		<!--<cpu:PushDIToStack/>-->

		<mm:CheckOut length="8"/>

		<!--<cpu:PullSIFromStack/>-->
		<cpu:PullAXFromStack/>
		<cpu:PushAXToStack/>
		<!--<cpu:PushSIToStack/>-->
		
		<cpu:CopyRegisterToOperand/>
		<op:AX-DIAddress/>

		<cpu:CopyRegisterToOperand/>
		<op:CX-AXRegister/>

		<cpu:DecrementAX/>
		
		<cpu:CopyRegisterToOperand/>
		<op:AX-DIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:CopyImmediateToAX/>
		<int>8</int>

		<cpu:PushDXToStack/>
		
		<obj:Create/>

		<cpu:PullDXFromStack/>

		<cpu:CopyRegisterToOperand/>
		<op:DX-SIRegister/>

		<cpu:CopyRegisterToOperand/>
		<op:CX-AXRegister/>

		<cpu:DecrementAX/>

		<lst:SetItem/>

		<!--<cpu:PullDIFromStack/>-->

		<cpu:LoopToRelative8/>
		<addressOf ref="forEachDevice" type="Relative8"/>

		<!--Create List Object-->
		<label id="createListObject"/>

		<cpu:PullAXFromStack/>

		<!--Get Item Count-->
		<cpu:CopyOperandToRegister/>
		<op:AX-DXAddress/>

		<cpu:IncrementAX/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:ShiftAXRegisterLeft/>
		<byte>2</byte>

		<cpu:PushAXToStack/>
		<cpu:PushSIToStack/>
		<cpu:PushDXToStack/>

		<cpu:CopyImmediateToDI/>
		<addressOf ref="ehciUsbPortList" type="Absolute32"/>

		<sys:GetCatalog/>

		<cat:FindType/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-BXRegister/>

		<cpu:PullDIFromStack/>
		<cpu:PullSIFromStack/>
		<cpu:PullAXFromStack/>

		<obj:Create/>

		<cpu:ReturnToNearCaller/>

		<var:string id="ehciUsbPort">http://metalx.org/Usb/Ehci/EhciUsbPort</var:string>
		<var:string id="ehciUsbPortList">http://metalx.org/Usb/Ehci/EhciUsbPortList</var:string>
	</cls:method>

	<cls:method name="GetRevision" type="http://metalx.org/Hexadecimal">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:Operand16/>
		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>2</byte>
		
		<hex:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetCommand" type="http://metalx.org/Hexadecimal">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<hex:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetStatus" type="http://metalx.org/Hexadecimal">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>

		<cpu:AddImmediateToAL/>
		<hex>04</hex>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<hex:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetInterruptEnable" type="http://metalx.org/Hexadecimal">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>

		<cpu:AddImmediateToAL/>
		<hex>08</hex>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<hex:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="GetCurrentFrame" type="http://metalx.org/Integer">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>

		<cpu:AddImmediateToAL/>
		<hex>0c</hex>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<int:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Reset" type="http://metalx.org/Usb/Ehci/EhciUsbController">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>
		
		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffffe</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIAddress/>

		<label id="wait"/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:TestAXWithImmediate/>
		<hex>00001000</hex>

		<cpu:BranchToRelative8IfZero/>
		<addressOf ref="wait" type="Relative8"/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>
		
		<cpu:OrAXWithImmediate/>
		<hex>00000002</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIAddress/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
	
	<cls:method name="Enable" type="http://metalx.org/Usb/Ehci/EhciUsbController">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:OrAXWithImmediate/>
		<hex>00000001</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIAddress/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Disable" type="http://metalx.org/Usb/Ehci/EhciUsbController">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<pcif:GetBaseAddress0/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffff0</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyImmediateToAX/>
		<int>0</int>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddress/>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIRegister/>

		<cpu:CopyOperandToRegister/>
		<op:AX-SIAddress/>

		<cpu:AndAXWithImmediate/>
		<hex>fffffffe</hex>

		<cpu:CopyRegisterToOperand/>
		<op:AX-SIAddress/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ToString" type="http://metalx.org/String">
		<cpu:CopyImmediateToDI/>
		<addressOf ref="deviceName" type="Absolute32"/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>

		<var:string id="deviceName">Universal Serial Bus 2.0 Controller</var:string>
	</cls:method>
	
	<cls:method name="GetClass" type="http://metalx.org/Class">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetType/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
</cls:class>